sgdk
tile_cache.h File Reference

SGDK Tile cache engine (tile VRAM management) More...

#include "vdp_tile.h"

Go to the source code of this file.

Classes

struct  TCBloc
 Tile cache bloc structure. More...
struct  TileCache
 Tile cache information structure. More...

Enumerations

enum  TCUpload { NO_UPLOAD, UPLOAD_VINT, UPLOAD_NOW }
 Tile cache upload action.

Functions

void TC_init ()
 Initialize the TileSet cache engine.
void TC_end ()
 End the TileSet cache engine.
void TC_createCache (TileCache *cache, u16 startIndex, u16 size)
 Initialize a new TileSet cache structure.
void TC_createCacheEx (TileCache *cache, u16 startIndex, u16 size, u16 numBloc)
 Initialize a new TileSet cache structure.
void TC_releaseCache (TileCache *cache)
 Release the TileSet cache structure.
void TC_clearCache (TileCache *cache)
 Clear the specified TileSet cache.
void TC_flushCache (TileCache *cache)
 Flush the specified TileSet cache.
s16 TC_alloc (TileCache *cache, TileSet *tileset, TCUpload upload)
 Allocate the specified TileSet in VRAM with given Tile cache and return its index.
If TileSet is already present in VRAM, no special operation is done else the TileSet will be automatically uploaded at the next VInt.
If the specified TileSet is compressed the method unpack it and store it in a temporary TileSet until it is send to VRAM.
s16 TC_reAlloc (TileCache *cache, TileSet *tileset)
 Re-allocate a TileSet which is still present in cache after a flush operation.
If the TileSet is not anymore in the tile cache the method return -1.
void TC_free (TileCache *cache, TileSet *tileset)
 Release VRAM allocation of the specified TileSet.
The tileSet remains in VRAM but will be the bloc will be marked as flushed so it can be overwritten by another bloc at any time.
s16 TC_getTileIndex (TileCache *cache, TileSet *tileset)
 Return the VRAM tile index of specified TileSet in the given Tile cache.
If the TileSet is not found then -1 is returned.
void TC_uploadAtVBlank (TileSet *tileset, u16 index)
 Will upload the specified Tileset at given VRAM tile position during VBlank.

Detailed Description

SGDK Tile cache engine (tile VRAM management)

Author:
Stephane Dallongeville
Date:
11/2013

Tile (in TileSet form) cache engine.
It offerts methods to manage VRAM usage for tile data.


Function Documentation

s16 TC_alloc ( TileCache cache,
TileSet tileset,
TCUpload  upload 
)

Allocate the specified TileSet in VRAM with given Tile cache and return its index.
If TileSet is already present in VRAM, no special operation is done else the TileSet will be automatically uploaded at the next VInt.
If the specified TileSet is compressed the method unpack it and store it in a temporary TileSet until it is send to VRAM.

Parameters:
cacheCache used for allocation.
tilesetThe TileSet to put in VRAM.
uploadUpload action, possible values are:
NO_UPLOAD don't upload tileset to VRAM (only return index)
UPLOAD_VINT upload to VRAM will be done automatically at VInt time (VBlank area)
UPLOAD_NOW upload to VRAM now
Returns:
the index of the TileSet in VRAM.
-1 if there is no enough available VRAM.
void TC_clearCache ( TileCache cache)

Clear the specified TileSet cache.

Parameters:
cacheCache we want to clear.
void TC_createCache ( TileCache cache,
u16  startIndex,
u16  size 
)

Initialize a new TileSet cache structure.

Parameters:
cacheCache to initialize.
startIndexTile start index in VRAM for the cache.
sizeSize in tile of the cache.

Set parameters and allocate some memory for the cache (~1KB).

void TC_createCacheEx ( TileCache cache,
u16  startIndex,
u16  size,
u16  numBloc 
)

Initialize a new TileSet cache structure.

Parameters:
cacheCache to initialize.
startIndexTile start index in VRAM for the cache.
sizeSize in tile of the cache.
numBlocNumber of bloc of the cache.

Set parameters and allocate some memory for the cache (~1KB).

void TC_end ( )

End the TileSet cache engine.

Release some memory and disable attached VInt processing.

void TC_flushCache ( TileCache cache)

Flush the specified TileSet cache.

Parameters:
cacheCache we want to flush.

This is not exactly the same as the clear operation:
Allocated tileset remains in cache but they can be erased with newly allocated tileset.

void TC_free ( TileCache cache,
TileSet tileset 
)

Release VRAM allocation of the specified TileSet.
The tileSet remains in VRAM but will be the bloc will be marked as flushed so it can be overwritten by another bloc at any time.

Parameters:
cacheCache used for allocation.
tilesetThe TileSet to release from VRAM.
s16 TC_getTileIndex ( TileCache cache,
TileSet tileset 
)

Return the VRAM tile index of specified TileSet in the given Tile cache.
If the TileSet is not found then -1 is returned.

Parameters:
cacheCache where to search the TileSet
tilesetThe TileSet we want to retrieve VRAM tile index.
Returns:
the index of the TileSet in VRAM.
-1 if not found.
void TC_init ( )

Initialize the TileSet cache engine.

Allocate some memory and enable VInt process.

s16 TC_reAlloc ( TileCache cache,
TileSet tileset 
)

Re-allocate a TileSet which is still present in cache after a flush operation.
If the TileSet is not anymore in the tile cache the method return -1.

Parameters:
cacheCache where we want to reallocate the TileSet.
tilesetThe TileSet to re allocate if possible.
Returns:
the index of the TileSet in VRAM.
-1 if the TileSet is not anymore in the cache.
See also:
TC_flushCache(TileCache *cache)
void TC_releaseCache ( TileCache cache)

Release the TileSet cache structure.

Parameters:
cacheCache we want to release.

Release memory used by TileSet cache structure (~1 KB).

void TC_uploadAtVBlank ( TileSet tileset,
u16  index 
)

Will upload the specified Tileset at given VRAM tile position during VBlank.

Parameters:
tilesetThe TileSet we want to upload to VRAM.
indexthe tile position where to upload in VRAM.
 All Classes Files Functions Variables Typedefs Enumerations Defines